<!--
 * @Author: your name
 * @Date: 2020-12-03 15:52:30
 * @LastEditTime: 2021-01-26 19:23:39
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\inventory\inventory_push.vue
-->
<template>
    <div>
        <el-dialog
        :title="$t('inventoryManage.pull')"
        :visible="newVisiblePvModules"
        width="700px"
        @close="()=>{$store.commit('setNewVisiblePvModules',false)}"
        :close-on-click-modal='false'
        >   
            <el-row :gutter="20">
                <el-col :span="19" :offset="2">
                    <el-form ref="form" :model="form" label-width="160px" >
                        <el-form-item :label="$t('version.versionService.fileURL')" prop="file" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <baseFile v-model="form.file" style="width:100%"  >
                            </baseFile>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="19" :offset="4">
                    <el-button type="primary" @click="downloadModal('form')">{{$t('download.templates')}}</el-button>
                    <span style="color:red;">{{$t('inventoryManage.pushMsg')}}</span>
                </el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setNewVisiblePvModules',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import baseFile from '../../components/common/baseFileInput'
export default {
    components: {
        baseFile
    },
    props: {
        getUserTypeFlag:{
            type:String,
            default:''
        }
    },
    data() {
        return {
            form:{
                file:''
            },
        };
    },
    computed: {
        newVisiblePvModules(){
            return this.$store.state.sysStore.newVisiblePvModules
        },
        userType(){
            return localStorage.getItem('userType')
        },
        lan(){
            return localStorage.getItem('lan')
        },
    },
    watch: {

    },
    created() {

    },
    mounted() {
    },
    methods: {
        downloadModal(){
            // window.open('wmsstock/downloadTemplate.do?lang='+this.lan)
            this.comm.windowOpen('/wmsstock/downloadTemplate')
        },
        async wmsproductinfoReceiveGoods(){
            let res = await this.API.wmsproductinfoReceiveGoods({
                file:this.form.file,
            })
            if(!res.success){
                this.comm.showMsg(false)
            }else{
                if(res.msg){
                    this.comm.showMsg(false,`${this.$t('inventoryManage.pullErroy3')}${res.msg}`)
                }else{
                    this.comm.showMsg(true)
                }
                this.$store.commit('setNewVisiblePvModules',false)
                this.$emit('uploadData',true)
            }
        },
        save(formName){
            this.$refs[formName].validate((valid) => {
              if (valid) {
                  this.wmsproductinfoReceiveGoods()
              } else {
                console.log('error submit!!');
                return false;
              }
            });
        },
    },
};
</script>

<style  lang="less" scoped>

</style>
